package com.turing.user.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.turing.common.util.Tools;
import com.turing.user.dao.RoleMapper;
import com.turing.user.entity.Role;
import com.turing.user.entity.RoleUser;
import com.turing.user.service.RoleService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @Description 服务类实现
* @Author livin
* @Date 2022-02-22
*/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {


    @Override
    public List<Role> getRolesByRoleIds(List<Integer> roleIds) {
        return new LambdaQueryChainWrapper<>(baseMapper).in(Role::getId, roleIds).list();
    }

    @Override
    public List<Integer> getRoleIdsByDataPrivileges(String dataPrivileges) {
        List<Role> roleList = new LambdaQueryChainWrapper<>(baseMapper).eq(Role::getClientPermissions, dataPrivileges).list();
        if(Tools.isNotEmpty(roleList)){
            return roleList.stream().map(Role::getId).collect(Collectors.toList());
        }
        return null;
    }

}
